November 13, 2024

The data (mtcars)

Graphs on the next slides use three variables from the mtcars data frame: mpg, hp, and cyl. Below are their values for the first 5 observations.

mtcars %>%
        select(c(mpg,hp,cyl)) %>%
        head(5)
##                    mpg  hp cyl
## Mazda RX4         21.0 110   6
## Mazda RX4 Wag     21.0 110   6
## Datsun 710        22.8  93   4
## Hornet 4 Drive    21.4 110   6
## Hornet Sportabout 18.7 175   8

Initial graph (ggplot2)

The first step is to build a plot using the ggplot2 package and to assign it to the variable plot1

Interactive graph (plotly)

Plotly’s ggplotly function enhances plot1 with interactivity (hover over graph for options)